| 123456789101112131415161718192021222324252627 |
- import { NextRequest, NextResponse } from 'next/server';
- import { ResultDto } from '@/dtos/response/common';
- import { LoginResponse } from '@/dtos/response/auth';
- import { fetchJson } from '@/lib/utils/server';
- export async function POST(request: NextRequest, { params }: { params: Promise<{ path: string[] }> }) {
- const { path } = await params;
- const endpoint = `/api/auth/${path.join('/')}`;
- const body = await request.json();
- const res: ResultDto = await fetchJson(endpoint, {
- method: 'POST',
- body: JSON.stringify(body)
- });
- const response = NextResponse.json(res);
- // 로그인 성공 시 쿠키 설정
- if (path[0] === 'login' && res.success && res.data) {
- const data = res.data as LoginResponse;
- const cookieOptions = { httpOnly: true, path: '/' };
- response.cookies.set('accessToken', data.accessToken, cookieOptions);
- response.cookies.set('refreshToken', data.refreshToken, cookieOptions);
- }
- return response;
- }
|